#include <assert.h>
#include <stdio.h>
#include "mus.h"

/* Mouse organism.  Mouse number of chromosomes. |CRHBP| is the array
containing the number of base pairs (bp) of each chromosome. The index
is the enumeration |CHROMOSOME_INDEX|. */

#define IS_EOSTR(ch) ((ch) == '\0')	/* end of string test */

static unsigned long long CHRBP[22] = {
	[chr1] = 197195432,
	[chr2] = 181748087,
	[chr3] = 159599783,
	[chr4] = 155630120,
	[chr5] = 152537259,
	[chr6] = 149517037,
	[chr7] = 152524553,
	[chr8] = 131738871,
	[chr9] = 124076172,
	[chr10] = 129993255,
	[chr11] = 121843856,
	[chr12] = 121257530,
	[chr13] = 120284312,
	[chr14] = 125194864,
	[chr15] = 103494974,
	[chr16] = 98319150,
	[chr17] = 95272651,
	[chr18] = 90772031,
	[chr19] = 61342430,
	[chrX] = 166650296,
	[chrY] = 15902555,
	[chrM] = 16299
};

inline unsigned long long get_mus_chromosome_nbps(enum mus_chromosome_index
						  chr_no)
{
	unsigned char idx = chr_no - 1;	/* index starts at zero and chromosome number at 1 */
	assert(idx <= MUS_NCHROMOSOMES);

	return CHRBP[idx];
}

inline enum mus_chromosome_index get_mus_chromosome_index(char *chr_str)
{
	assert(chr_str);
	enum mus_chromosome_index id;	/* chromosome identification */

	if (chr_str[3] == 'X' && IS_EOSTR(chr_str[4]))
		return chrX;
	else if (chr_str[3] == 'Y' && IS_EOSTR(chr_str[4]))
		return chrY;
	else if (chr_str[3] == 'M' && IS_EOSTR(chr_str[4]))
		return chrM;
	else if (IS_EOSTR(chr_str[4]) || IS_EOSTR(chr_str[5])) {
		id = atoi(&chr_str[3]);
		return id - 1;
	}
	return chr_error;
}

/* |print_nbps_chromosomes| prints the number of base pairs per
   chromosome on the screen. */
void print_nbps_chromosomes(void)
{
	unsigned char i;

	for (i = chr1; i < MUS_NCHROMOSOMES; i++)
		printf("%u\t%llu\n", i + 1, get_mus_chromosome_nbps(i));
}
